import { Controller } from 'egg';
import moment from 'moment';
export default class HomeController extends Controller {
  public async index() {
    const { ctx } = this;
    // const user = ctx.session.user;
    console.log('home index');
    // if (!user) {
    //   return ctx.redirect('login');
    // }

    let res = await this.service.version.getList();

    console.log(res);
    await ctx.render('home/home', {
      list: res.map((item) => {
        return {
          id: item.id,
          version: item.version,
          remark: item.remark,
          public: item.public === 1,
          create_time: moment(item.create_time).format('YYYY-MM-DD HH:mm:ss')
        };
      })
    });
  }

  public async add() {
    const { ctx } = this;
    await ctx.render('home/add');
  }
}
